import 'package:flutter/material.dart';
import 'package:flutter_uxin/HomeWork/request/HomeworkRequestManager.dart';


enum onTapType {
  sendHomework,
  showHomeworkList
}


class HomeWorkTeacherRootPage extends StatefulWidget{
  HomeWorkTeacherRootPage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _HomeWorkTeacherRootPageState createState() => _HomeWorkTeacherRootPageState();

}

class _HomeWorkTeacherRootPageState extends State<HomeWorkTeacherRootPage> {




  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Container(
        color :Color(0xffeaeaea),
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: ListView(
          children: <Widget>[
            TeacherHomeWorkWidget("lib/HomeWork/images/work_yx.png","预习作业",onTap: (tapType){

            }),
            TeacherHomeWorkWidget("lib/HomeWork/images/work_lx.png","离线作业",onTap: (tapType){

            }),
            TeacherHomeWorkWidget("lib/HomeWork/images/work_ws.png","网上作业",onTap: (tapType){

            }),
            TeacherHomeWorkWidget("lib/HomeWork/images/work_tz.png","拓展作业",onTap: (tapType){

            }),
          ],
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class TeacherHomeWorkWidget extends StatelessWidget {

  String typeIcon;
  String typeTitle;
  @required ValueChanged<onTapType> onTap;

  TeacherHomeWorkWidget(this.typeIcon, this.typeTitle, {this.onTap});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          TeacherHomeWorkTopWidget(typeIcon,typeTitle,onTap: (tapType){

          }),
          TeacherHomeWorkEmptyWidget(typeTitle),

        ],
      ),
      margin: EdgeInsets.all(10.0), // 外边距
      padding: EdgeInsets.all(5.0), // 内边距
      decoration: BoxDecoration( //Container样式
        color: Colors.white, // 背景色
        borderRadius: BorderRadius.circular(10.0), // 圆角边框
      ),
    );
  }

}
class TeacherHomeWorkTopWidget extends StatelessWidget {
  String typeIcon;
  String typeTitle;
  @required ValueChanged<onTapType> onTap;

  TeacherHomeWorkTopWidget(this.typeIcon,this.typeTitle,{this.onTap});
  @override
  Widget build(BuildContext context) {
    return Container(
        child: Column(
          children: <Widget>[
            Container(
              color: Colors.white,
              height: 24,
              child: _mineItem(typeIcon, typeTitle),
            ),
            Container(
              color: Color(0xffeaeaea),
              constraints: BoxConstraints.expand(height: 1.0),
            ),
          ],
        )
    );
  }

  Widget _mineItem(String imageName,String title) {
    return Row(
      children: <Widget>[
        Expanded(
          flex: 1,
          child:Row(children: <Widget>[
            Container(
              padding: EdgeInsets.only(left: 0),
              child: Image.asset(
                imageName,
                width: 30,
                height: 30,
              ),
            ),
            Container(
              padding: EdgeInsets.only(left: 0),
              child: Text(
                title,
                style: TextStyle(fontSize: 14),
              ),
            ),


          ]) ,
        ),

        Container(

          child:Row(children: <Widget>[
            Container(
              padding: EdgeInsets.only(left: 0),
              child: Image.asset(
                'lib/HomeWork/images/buzhi_ico.png',
                width: 15,
                height: 15,
              ),
            ),
            Container(
              padding: EdgeInsets.only(right:5),
              child: GestureDetector(
                child: Text(
                  '布置',
                  textAlign: TextAlign.right,
                  style: TextStyle(
                    fontSize: 14.0,
                    color: Color(0xff1F98FF),
                  ),
                ),

                onTap: () {

                  this.onTap(onTapType.sendHomework);
                },
              ),
            ),


          ]) ,
        ),
      ],
    );
  }
}


class TeacherHomeWorkEmptyWidget extends StatelessWidget {

  String typeTitle;


  TeacherHomeWorkEmptyWidget(this.typeTitle);
  @override
  Widget build(BuildContext context) {
    return Container(
        padding: EdgeInsets.only(left: 10,right: 10),
        height: 90,
        child: Column(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(top:10),
              child: Image.asset(
                'lib/HomeWork/images/logo_gray.png',
                width: 168,
                height: 26,
              ),
            ),
            Container(
              padding: EdgeInsets.only(top: 15),
              child: Text.rich(
                  TextSpan(
                      children: [

                        TextSpan(
                          text: '暂无${typeTitle},快去',
                          style: TextStyle(
                            fontSize: 16.0,
                            color: Color(0xff929292),
                          ),
                        ),
                        TextSpan(
                          text: '布置',
                          style: TextStyle(
                            fontSize: 16.0,
                            color: Color(0xff1F98FF),
                          ),
                        ),
                        TextSpan(
                          text: '${typeTitle}吧',
                          style: TextStyle(
                            fontSize: 16.0,
                            color: Color(0xff929292),
                          ),
                        )




                      ]
                  )
              ),
            ),
          ],
        )
    );
  }


}

// 分割线
Widget get _listViewLine {
  return Container(
    color: Color(0xffeaeaea),
    height: 6,
  );
}